package com.stsdai.portal.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stsdai.manager.pojo.Content;
import com.stsdai.manager.pojo.Item;
import com.stsdai.manager.service.ContentCategoryService;
import com.stsdai.manager.service.ContentService;
import com.stsdai.manager.service.ItemService;

@Controller
@RequestMapping("index")
public class IndexController {

	@Value("${STSDAI_PORTAL_AD}")
	private Long categoryId;

	@Autowired
	private ContentCategoryService categoryService;
	
	@Autowired
	private ContentService contentService;
	
	@Autowired
	private ItemService itemService;

	// http://127.0.0.1:8083/index.html
	@RequestMapping
	public String index(Model model) {
		// 使用内容服务，查询大广告数据
		String AD = this.contentService.queryContentByCategoryId(this.categoryId);
		// 把大广告数据放到Model，传递给前台页面
		model.addAttribute("AD", AD);

		// 查询商品分类信息返回JSON格式字符串
		String allCategory = this.categoryService.findAllContentCategory();
		// 把json格式的string放到Model中,传到前端
		model.addAttribute("allCategory", allCategory);
		
		//查询最新商品
		List<Item> newItem = this.itemService.queryNewItem();
		model.addAttribute("newItem", newItem);
		
		//查询有机蔬菜
		List<Item> youJiCai = this.itemService.queryYouJiCai();
		model.addAttribute("youJiCai", youJiCai);
		
		//查询时令水果
		List<Item> shiLingGuo = this.itemService.queryShiLingGuo();
		model.addAttribute("shiLingGuo", shiLingGuo);
		
		//查询有机蔬菜的左侧广告
		Content leftContent1 = this.contentService.queryLeftYouJi();
		model.addAttribute("leftContent1", leftContent1);
		
		//查询时令水果左侧广告
		Content leftContent2 = this.contentService.queryLeftShiLing();
		model.addAttribute("leftContent2", leftContent2);
		
		//查询精品分类广告
		List<Content> jingPing = this.contentService.queryLeftJingPing();
		model.addAttribute("jingPing", jingPing);

		return "index";
	}
}
